package com.hontech.bv.conn

import com.hontech.bv.conn.serial.SerialType

class WriteFrame (val req: Int, val dest: Int, val args: Array<SerialType>) {

    companion object {
        var globalSeq = 0
            private set
        const val SEQ_MAX = 15
    }

    val seq: Int

    init {
        if (globalSeq > SEQ_MAX) {
            globalSeq = 0
        }
        seq = globalSeq
        globalSeq ++
    }

    fun promiseIndex() = (req shl 8) + seq

    fun info(): String {
        return "${Proto.nameId(dest)} ${Proto.nameReq(req)}"
    }
}